home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / libraries / streams / internals.dylan next >
Encoding:
Text File  |  1995-03-15  |  3.1 KB  |  94 lines  |  [TEXT/ttxt]

  1. module: Internals
  2. author: chiles@cs.cmu.edu
  3. synopsis: This file implements some extensions to the Gwydion Dylan
  4.           implementation.
  5. copyright: See below.
  6. rcs-header: $Header: internals.dylan,v 1.9 94/11/04 14:40:20 chiles Exp $
  7.  
  8. //======================================================================
  9. //
  10. // Copyright (c) 1994  Carnegie Mellon University
  11. // All rights reserved.
  12. // 
  13. // Use and copying of this software and preparation of derivative
  14. // works based on this software are permitted, including commercial
  15. // use, provided that the following conditions are observed:
  16. // 
  17. // 1. This copyright notice must be retained in full on any copies
  18. //    and on appropriate parts of any derivative works.
  19. // 2. Documentation (paper or online) accompanying any system that
  20. //    incorporates this software, or any part of it, must acknowledge
  21. //    the contribution of the Gwydion Project at Carnegie Mellon
  22. //    University.
  23. // 
  24. // This software is made available "as is".  Neither the authors nor
  25. // Carnegie Mellon University make any warranty about the software,
  26. // its performance, or its conformity to any specification.
  27. // 
  28. // Bug reports, questions, comments, and suggestions should be sent by
  29. // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  30. //
  31. //======================================================================
  32. //
  33.  
  34.  
  35.  
  36. ///
  37. /// Classes and types.
  38. ///
  39.  
  40. define constant <byte> =
  41.   limited(<fixed-integer>, min: 0, max: 255);
  42.  
  43.  
  44. ///
  45. /// As methods.
  46. ///
  47.  
  48. define method as (result :: singleton(<byte>), object :: <byte-character>)
  49.     => result :: <byte>;
  50.   as(<integer>, object);
  51. end method;
  52.  
  53. define method as (result :: singleton(<byte-string>), object :: <byte-vector>)
  54.     => result :: <byte-string>;
  55.   let len :: <fixed-integer> = object.size;
  56.   let res :: <byte-string> = make(<byte-string>, size: len);
  57.   copy-bytes(res, 0, object, 0, len);
  58. end method;
  59.  
  60. define method as (result :: singleton(<byte-vector>), object :: <byte-string>)
  61.     => result :: <byte-vector>;
  62.   let len :: <fixed-integer> = object.size;
  63.   let res :: <byte-vector> = make(<byte-vector>, size: len);
  64.   copy-bytes(res, 0, object, 0, len);
  65. end method;
  66.  
  67.  
  68. ///
  69. /// Utilities.
  70. ///
  71.  
  72. /// call-fd-function -- Exported.
  73. ///
  74. /// This function applies the fd function to the arguments and tests the
  75. /// error code.  If there is no error, return the function's values;
  76. /// otherwise, signal an error with the unix description of the error.
  77. ///
  78. /// If we had macros, this function would be a macro and require no
  79. /// overhead.  It also would allow type propagation so that calls to these
  80. /// fd functions within expression (that is, not bound to a type-declared
  81. /// variable) would have the benefit of the return types of the fd
  82. /// functions.  As it is, we have to allocate a rest argument, do multiple
  83. /// function calls, and so on.  For now, assume the system call incurs more
  84. /// overhead, especially if William really implemented rest args as
  85. /// more-args.
  86. ///
  87. /// IGNORE MULTIPLE VALUES FOR NOW.
  88. ///
  89. define method call-fd-function (fun :: <function>, #rest args)
  90.   let (res, err) = apply(fun, args);
  91.   if (err) error(fd-error-string(err)) end;
  92.   res;
  93. end;
  94.